﻿/*
 * Created by SharpDevelop.
 * User: Leandro
 * Date: 22/03/2014
 * Time: 03:59 p.m.
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Linq;

namespace Gestión_UTN
{
    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public partial class MainForm : Form
    {
        public bool logueado;

        public bool Logueado
        {
            get { return logueado; }
            set { this.logueado = value; }
        }

        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // TODO: Add constructor code after the InitializeComponent() call.
            //
        }


        void PctAlumnosClick(object sender, EventArgs e)
        {
            Form existe = Application.OpenForms.OfType<Form>().Where(pre => pre.Name == "Alumnos").SingleOrDefault<Form>();

            if (existe != null)
            {
                existe.WindowState = FormWindowState.Normal;
            }
            else
            {
                Gestión_UTN.View.general.Alumnos alumnos = new Gestión_UTN.View.general.Alumnos();
                alumnos.StartPosition = FormStartPosition.CenterScreen;
                alumnos.Show();
            }
        }

        void PctAlumnosMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Alumnos";
        }


        void PctAlumnosMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        void PctProfesoresMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Profesores";
        }

        void PctProfesoresMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        void PctAdministracionMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Administración";
        }

        void PctAdministracionMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        void PctInscripcionesMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Inscripciones";
        }

        void PctInscripcionesMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        void PctReportesMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Reportes";
        }

        void PctReportesMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        void PctExamenesMouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Acceso Módulo Exámenes";
        }

        void PctExamenesMouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Principal";
        }

        private void pctAdministracion_Click(object sender, EventArgs e)
        {
            Form existe = Application.OpenForms.OfType<Form>().Where(pre => pre.Name == "MainAdministracion").SingleOrDefault<Form>();

            if (existe != null)
            {
                existe.WindowState = FormWindowState.Normal;
            }
            else
            {
                View.main.MainAdministracion administracion = new View.main.MainAdministracion();
                administracion.StartPosition = FormStartPosition.CenterScreen;
                administracion.Show();
            }
        }

        private void pctProfesores_Click(object sender, EventArgs e)
        {
            Form existe = Application.OpenForms.OfType<Form>().Where(pre => pre.Name == "MainProfesores").SingleOrDefault<Form>();

            if (existe != null)
            {
                existe.WindowState = FormWindowState.Normal;
            }
            else
            {
                View.main.MainProfesores profesores = new View.main.MainProfesores();
                profesores.StartPosition = FormStartPosition.CenterScreen;
                profesores.Show();
            }
        }

        private void pctInscripciones_Click(object sender, EventArgs e)
        {
            Form existe = Application.OpenForms.OfType<Form>().Where(pre => pre.Name == "MainInscripciones").SingleOrDefault<Form>();

            if (existe != null)
            {
                existe.WindowState = FormWindowState.Normal;
            }
            else
            {
                View.main.MainInscripciones inscripciones = new View.main.MainInscripciones();
                inscripciones.StartPosition = FormStartPosition.CenterScreen;
                inscripciones.Show();
            }
        }

        private void pctExamenes_Click(object sender, EventArgs e)
        {
            Form existe = Application.OpenForms.OfType<Form>().Where(pre => pre.Name == "MainExamenes").SingleOrDefault<Form>();

            if (existe != null)
            {
                existe.WindowState = FormWindowState.Normal;
            }
            else
            {
                View.main.MainExamenes examenes = new View.main.MainExamenes();
                examenes.StartPosition = FormStartPosition.CenterScreen;
                examenes.Show();
            }
        }

        private void picLogin_MouseHover(object sender, EventArgs e)
        {
            this.lblStatus.Text = (logueado)
                ? "Cerrar Sesión"
                : "Iniciar Sesión";
        }

        private void picLogin_MouseLeave(object sender, EventArgs e)
        {
            this.lblStatus.Text = "Pantalla Inicial";
        }

        private void picLogin_Click(object sender, EventArgs e)
        {
            if (logueado)
            {
                DialogResult resp = MessageBox.Show("¿Desea Cerrar Sesión?", "Salir", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (resp == System.Windows.Forms.DialogResult.Yes)
                {
                    Logueado = false;

                    Sesion();
                }
            }
            else
            {
                View.general.Login login = new View.general.Login();

                login.StartPosition = FormStartPosition.CenterScreen;

                if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Logueado = true;

                    Sesion();
                }
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.pctAdministracion.Enabled = false;
            this.pctAlumnos.Enabled = false;
            this.pctExamenes.Enabled = false;
            this.pctInscripciones.Enabled = false;
            this.pctProfesores.Enabled = false;
            this.pctReportes.Enabled = false;

            Logueado = false;
        }

        private void Sesion()
        {
            if (Logueado)
            {
                this.pctAdministracion.Enabled = true;
                this.pctAlumnos.Enabled = true;
                this.pctExamenes.Enabled = true;
                this.pctInscripciones.Enabled = true;
                this.pctProfesores.Enabled = true;
                this.pctReportes.Enabled = true;
            }
            else
            {
                this.pctAdministracion.Enabled = false;
                this.pctAlumnos.Enabled = false;
                this.pctExamenes.Enabled = false;
                this.pctInscripciones.Enabled = false;
                this.pctProfesores.Enabled = false;
                this.pctReportes.Enabled = false;
            }
        }
    }
}
